/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import ru.jSky.finder.FinderByEdidFacade;
import ru.jSky.factory.BridgeFactory;
import ru.jSky.factory.FinderByEdidFactory;
import ru.jSky.interfaces.JSkyMod;
import ru.jSky.support.GrupTypeBuilder;
import skyproc.GRUP_TYPE;
import skyproc.ModListing;
import skyproc.SPGlobal;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class MatcherTestWithMods {

    private BridgeFactory bridgeFactory;
    private JSkyMod creatingMod;
    private FinderByEdidFactory finderFactory;
    private FinderByEdidFacade finder;

    protected GRUP_TYPE[] getImportedGrupTypes() {
        GrupTypeBuilder typeBuilder = new GrupTypeBuilder();
        typeBuilder.ALL();
        return typeBuilder.build();
    }

    protected JSkyMod createMerger() {
        SyntaticModBuilder builder = new SyntaticModBuilder();
        builder.add("Skyrim.esm");
        return builder.build();
    }

    @BeforeMethod
    public void setUp() {
        initSettings();
        bridgeFactory = new BridgeFactory();
        creatingMod = getBridgeFactory().createBridge(SPGlobal.getGlobalPatch());
        finderFactory = new FinderByEdidFactory();
        finder = FinderByEdidFacade.create();
    }

    private void initSettings() {
        try {
            JSkyGlobal.getInstance().beginCreatingMod("Rakev", "Test");
            JSkyGlobal.getInstance().setPathToData("C:\\Steam\\SteamApps\\common\\skyrim\\Data\\");
            ModListing importingMod = new ModListing("Skyrim.esm");
            ModImporter.getInstance().importMod(importingMod, getImportedGrupTypes());
        } catch (MissingMaster | BadMod ex) {
            ex.printStackTrace();
            RuntimeException newEx = new IllegalStateException("Init error");
            newEx.addSuppressed(ex);
            throw newEx;
        }
    }

    protected FinderByEdidFactory getFinderFactory() {
        return finderFactory;
    }

    /**
     * @return the merger
     */
    protected JSkyMod getMerger() {
        return new CompositeMod(ModImporter.getInstance().getImportedMods());
    }

    /**
     * @return the bridgeFactory
     */
    protected BridgeFactory getBridgeFactory() {
        return bridgeFactory;
    }

    /**
     * @return the creatingMod
     */
    protected JSkyMod getCreatingMod() {
        return creatingMod;
    }

    public FinderByEdidFacade getFinderFacade() {
        return finder;
    }
}
